package com.dotstone.chipism.activity;

import com.dotstone.chipism.R;
import com.dotstone.chipism.bean.DeviceType;
import com.dotstone.chipism.util.ToastShow;
import com.dotstone.chipism.view.slidingfragmenu.BarUtils;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class DIYActivity extends BaseActivity {
	private LinearLayout mBackL;
	private TextView mStatusBar;
	private TextView mTitleTv;
	private TextView mTypeT;
	private TextView mModeT;
	private Button mNextB;
	private Dialog dialog;
	private Button mTypeB1;
	private Button mTypeB2;
	private Button mTypeB3;
	private Button mTypeB4;
	private Button mTypeB5;
	private Button mTypeB6;
	private Button mTypeB7;
	private Button mTypeB8;
	private Button mTypeB9;
	private Button mTypeB10;
	public static DIYActivity diyActivity;
	// private MySocket socket;
	private int type = DeviceType.DEVICE_TYPE_TV;

	@Override
	public void widgetClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back_layout:
			finish();
			break;
		case R.id.type_tv:
			// 显示类型选择dialog
			dialog = new Dialog(DIYActivity.this, R.style.MyDialogStyle);
			dialog.setContentView(R.layout.dialog_type_selection);
			Window dialogWindow = dialog.getWindow();
			WindowManager.LayoutParams lp = dialogWindow.getAttributes();
			dialogWindow.setGravity(Gravity.CENTER);
			lp.width = LayoutParams.FILL_PARENT;
			dialogWindow.setAttributes(lp);
			mTypeB1 = (Button) dialog.findViewById(R.id.type_btn1);
			mTypeB2 = (Button) dialog.findViewById(R.id.type_btn2);
			mTypeB3 = (Button) dialog.findViewById(R.id.type_btn3);
			mTypeB4 = (Button) dialog.findViewById(R.id.type_btn4);
			mTypeB5 = (Button) dialog.findViewById(R.id.type_btn5);
			mTypeB6 = (Button) dialog.findViewById(R.id.type_btn6);
			mTypeB7 = (Button) dialog.findViewById(R.id.type_btn7);
			mTypeB8 = (Button) dialog.findViewById(R.id.type_btn8);
			mTypeB9 = (Button) dialog.findViewById(R.id.type_btn9);
			mTypeB10 = (Button) dialog.findViewById(R.id.type_btn10);
			mTypeB1.setOnClickListener(this);
			mTypeB2.setOnClickListener(this);
			mTypeB3.setOnClickListener(this);
			mTypeB4.setOnClickListener(this);
			mTypeB5.setOnClickListener(this);
			mTypeB6.setOnClickListener(this);
			mTypeB7.setOnClickListener(this);
			mTypeB8.setOnClickListener(this);
			mTypeB9.setOnClickListener(this);
			mTypeB10.setOnClickListener(this);
			dialog.show();
			break;
		case R.id.mode_tv:
			ToastShow.Show(getApplicationContext(), "尚无更多模版");
			break;
		case R.id.nextstep1:
			if (type != DeviceType.DEVICE_TYPE_AIR_CONTROLLER) {
				Intent intent = new Intent(DIYActivity.this, DIYActivity1.class);
				intent.putExtra("type", type);
				startActivity(intent);
			} else {
				Intent intent = new Intent(DIYActivity.this, DIYAirRemoteActivity.class);
				intent.putExtra("type", type);
				startActivity(intent);
			}
			break;
		case R.id.type_btn1:
			mTypeT.setText(mTypeB1.getText());
			type = DeviceType.DEVICE_TYPE_TV;
			mModeT.setText(mTypeB1.getText() + getString(R.string.remote_mode1));
			dialog.dismiss();
			break;
		case R.id.type_btn2:
			mTypeT.setText(mTypeB2.getText());
			type = DeviceType.DEVICE_TYPE_AIR_CONTROLLER;
			mModeT.setText(mTypeB2.getText() + getString(R.string.remote_mode1));
			dialog.dismiss();
			break;
		case R.id.type_btn3:
			mTypeT.setText(mTypeB3.getText());
			type = DeviceType.DEVICE_TYPE_FAN;
			mModeT.setText(mTypeB3.getText() + getString(R.string.remote_mode1));
			dialog.dismiss();
			break;
		case R.id.type_btn4:
			mTypeT.setText(mTypeB4.getText());
			type = DeviceType.DEVICE_TYPE_AUDIO;
			mModeT.setText(mTypeB4.getText() + getString(R.string.remote_mode1));
			dialog.dismiss();
			break;
		case R.id.type_btn5:
			mTypeT.setText(mTypeB5.getText());
			type = DeviceType.DEVICE_TYPE_SATELLITE;
			mModeT.setText(mTypeB5.getText() + getString(R.string.remote_mode1));
			dialog.dismiss();
			break;
		case R.id.type_btn6:
			mTypeT.setText(mTypeB6.getText());
			type = DeviceType.DEVICE_TYPE_DVD;
			mModeT.setText(mTypeB6.getText() + getString(R.string.remote_mode1));
			dialog.dismiss();
			break;
		case R.id.type_btn7:
			mTypeT.setText(mTypeB7.getText());
			type = DeviceType.DEVICE_TYPE_PROJECTOR;
			mModeT.setText(mTypeB7.getText() + getString(R.string.remote_mode1));
			dialog.dismiss();
			break;
		case R.id.type_btn8:
			mTypeT.setText(mTypeB8.getText());
			type = DeviceType.DEVICE_TYPE_BOX2;
			mModeT.setText(mTypeB8.getText() + getString(R.string.remote_mode1));
			dialog.dismiss();
			break;
		case R.id.type_btn9:
			mTypeT.setText(mTypeB9.getText());
			type = DeviceType.DEVICE_TYPE_CAMERA;
			mModeT.setText(mTypeB9.getText() + getString(R.string.remote_mode1));
			dialog.dismiss();
			break;
		case R.id.type_btn10:
			mTypeT.setText(mTypeB10.getText());
			type = DeviceType.DEVICE_TYPE_DENG;
			mModeT.setText(mTypeB10.getText() + getString(R.string.remote_mode1));
			dialog.dismiss();
			break;
		default:
			break;
		}
	}

	@Override
	public void initParms(Bundle parms) {
		// TODO Auto-generated method stub

	}

	@Override
	public View bindView() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int bindLayout() {
		// TODO Auto-generated method stub
		return R.layout.activity_diy;
	}

	@Override
	public void initView(View view) {
		// TODO Auto-generated method stub
		mBackL = $(R.id.back_layout);
		mStatusBar = $(R.id.tv_statusBar_mian);
		mTitleTv = $(R.id.title_tv);
		mTitleTv.setText("DIY");
		mTypeT = $(R.id.type_tv);
		mModeT = $(R.id.mode_tv);
		mNextB = $(R.id.nextstep1);
		diyActivity = this;
		boolVersion();
		mBackL.setOnClickListener(this);
		mTypeT.setOnClickListener(this);
		mModeT.setOnClickListener(this);
		mNextB.setOnClickListener(this);
		// socket = SocketManager.getInstance().sMap.get(DeviceManager
		// .getInstance().getmWlanId());
	}

	@Override
	public void setListener() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doBusiness(Context mContext) {
		// TODO Auto-generated method stub

	}

	public void boolVersion() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

			Window window = getWindow();
			window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
					WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
			// 透明导航栏
			// getWindow().addFlags(
			// WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
			// 改变titlebar的高度
			int statusbarHeight = BarUtils.getStatusBarHeight(this);
			RelativeLayout.LayoutParams layoutParams1 = (RelativeLayout.LayoutParams) mStatusBar.getLayoutParams();
			layoutParams1.height = statusbarHeight;
			mStatusBar.setLayoutParams(layoutParams1);
			mStatusBar.setVisibility(View.VISIBLE);
		} else {
			mStatusBar.setVisibility(View.GONE);
		}
	}

}
